using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace Main.AStar
{
    public class Node : IComparable<Node>
    {
        /// <summary>
        /// 当前网格总消耗
        /// </summary>
        public int FCost => gCost + hCost;

        [Header("网格坐标")] public Vector2Int gridPos;
        [Header("距离起点坐标消耗")] public int gCost;
        [Header("距离终点坐标消耗")] public int hCost;
        [Header("当前网格是否为障碍")] public bool isObstacle;
        [Header("父节点")] public Node parentNode;
        public Node(Vector2Int pos)
        {
            gridPos = pos;
            parentNode = null;
        }

        /// <summary>
        /// 使用FCost比较
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(Node other)
        {
            // 先判断FCost的大小
            int result = FCost.CompareTo(other.FCost);

            // FCost相等时使用HCost离终点距离判断
            if (result == 0)
            {
                result = hCost.CompareTo(other.hCost);
            }
            return result;
        }
    }
}